package com.gidgabs.modules.base.controller;

import java.util.List;
import java.util.Map;

import com.gidgabs.common.utils.PageUtils;
import com.gidgabs.common.utils.Query;
import com.gidgabs.common.utils.R;
import com.gidgabs.modules.base.service.TbCompanyService;
import com.gidgabs.modules.entity.TbCompanyEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 公司信息表
 * 
 * @author lanyonglin
 * @email www.baidu.com
 * @date 2018-06-07 18:07:05
 */
@RestController
@RequestMapping("/loca/company")
public class TbCompanyController {
	@Autowired
	private TbCompanyService companyService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TbCompanyEntity> companyList = companyService.queryList(query);
		int total = companyService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(companyList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Integer id){
		TbCompanyEntity company = companyService.queryObject(id);
		
		return R.ok().put("company", company);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody TbCompanyEntity company){
		companyService.save(company);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody TbCompanyEntity company){
		companyService.update(company);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Integer[] ids){
		companyService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
